﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace Infrastructure.WpfClient.Views.ExceptionBox
{
    /// <summary>
    /// Interaction logic for ExceptionBox.xaml
    /// </summary>
    public partial class ExceptionBox : Window, IExceptionBoxView
    {
        private ExceptionBoxPresenter _Presenter;
        [Dependency]
        public ExceptionBoxPresenter Presenter
        {
            set
            {
                _Presenter = value;
                _Presenter.View = this;
                this.DataContext = _Presenter;
            }
            get { return _Presenter; }
        }
        public ExceptionBox()
        {
            InitializeComponent();
        }

        
        private Exception _CurrentException;
        public Exception CurrentException
        {
            get { return this._CurrentException; }
            set
            {

                this._CurrentException = value;
                this.lblErrorMessage.Text = value.Message;
                this.lblErrorDetail.Text = value.StackTrace;
            }
        }        
        public string ExceptionBoxTitle { get { return this.lblTitle.Content.ToString(); } set { this.lblTitle.Content = value; } }
        public byte[] CurrentImage
        {
            get
            {
                var printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
                Graphics graphics = Graphics.FromImage(printscreen as System.Drawing.Image);
                graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                printscreen.Save(stream, ImageFormat.Jpeg);
                return stream.ToArray();
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }
        private void btnCopyToClipboard_Click(object sender, RoutedEventArgs e)
        {
            this.Presenter.CopyToClipboard();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void btnSendMail_Click(object sender, RoutedEventArgs e)
        {
            this.Presenter.SendEmail();
        }
        
    }
}
